/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Department;
import DataConnect.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
/**
 *
 * @author MyLaptop
 */
public class Department {
    public int departmentID;
    public String departmentName;
    
    public Department()
    {
        
    }

    public int getDepartmentID() {
        return departmentID;
    }

    public String getDepartmentName() {
        return departmentName;
    }

    public void setDepartmentID(int departmentID) {
        this.departmentID = departmentID;
    }

    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }
    
    public static Vector getAllDepartment() throws SQLException{
        Vector v = new Vector();
        try {
            ResultSet rs = DBHelper.executeQuery("spGetAllDepartment");
            while(rs.next()){
                Department obj = new Department();
                obj.departmentID = rs.getInt(1);
                obj.departmentName = rs.getString(2);
                v.add(obj);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;
    }
    
    public static Vector searchDepartmentByName(Vector name) throws SQLException{
        Vector v = new Vector();
        try {
            ResultSet rs = DBHelper.executeQuery("spSearchDepartmentByName",name);
            while(rs.next()){
                Department obj = new Department();
                obj.departmentID = rs.getInt(1);
                obj.departmentName = rs.getString(2);
                v.add(obj);
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;
    }
    
    public static int insertDepartment(Department obj) throws SQLException {
        int i = 0;
        try {
            Vector paramList = new Vector();
            paramList.add(obj.departmentName);
                       
            i = DBHelper.executeUpdate("spInsertDepartment",paramList);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return i;
    }
    public static int updateDepartment(Department obj) throws SQLException {
        int i=0;
        try {            
            Vector paramList = new Vector();
            paramList.add(obj.departmentID);
            paramList.add(obj.departmentName);
           
            i = DBHelper.executeUpdate("spUpdateDepartment",paramList);
        } catch(SQLException sqlex) {
            
        }
        return i;
    }
    
    public static int deleteDepartment(String departmentName) throws SQLException {
        int i=0;
        try {
            Vector paramList=new Vector();
            paramList.add(departmentName);
            i=DBHelper.executeUpdate("spDeleteDepartment",paramList);
        } catch(SQLException sqlex) {            
        }
        return i;
    }
    
}
